package com.ssyu.dome.service;

import java.util.ArrayList;
import java.util.List;

import com.ssyu.dome.common.DBUtil;
import com.ssyu.dome.entity.UserEntity;

public class UserService {
	/**
	 * 登录
	 */
	public UserEntity login(UserEntity user) {
		String sql = "select * from user where email=? and password=?";
		return DBUtil.getUniqueResult(UserEntity.class, sql, user.getEmail(),
				user.getPassword());
	}
	/**
	 * 注册
	 */
	
	public int addAccount(UserEntity user){
		String sql = "insert into user values(null,?,?,?,?,?,?)";
		List<Object> paramList = new ArrayList<Object>();
		paramList.add(0, user.getEmail());
		paramList.add(1, user.getPassword());
		paramList.add(2, user.getUsername());
		paramList.add(3, user.getPhone());
		paramList.add(4, user.getRoleType());
		paramList.add(5, user.getIsActive());
		return DBUtil.executeUpdate(sql, paramList);
	}
	/**
	 * 信息绑定
	 * @param user
	 */
	public void bindInfoService(UserEntity user) {
		String sql = "UPDATE user SET username=?, phone=? WHERE id=?";
		DBUtil.executeUpdate(sql, user.getUsername(),user.getPhone(),user.getId());
	}

}
